package com.tanhua.dubbo.api.impl.mongo;
import org.bson.types.ObjectId;

import com.tanhua.domain.mongo.UserLike;
import com.tanhua.domain.mongo.UserUnLike;
import com.tanhua.dubbo.api.mongo.UserUnLikeApi;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@Service
public class UserUnLikeApiImpl implements UserUnLikeApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 查询是否存在这个不喜欢这个用户
     */
    @Override
    public boolean exitLove(Long userId, Long recommendUserId){
        Query query = new Query(Criteria.where("userId").is(userId)
                .and("unlikeUserId").is(recommendUserId));
        boolean flag = mongoTemplate.exists(query, UserUnLike.class);
        return flag;
    }

    /**
     * 添加不喜欢
     */
    @Override
    public void save(Long userId, Long unlikeId) {
        UserUnLike userUnLike = new UserUnLike();
        userUnLike.setId(ObjectId.get());
        userUnLike.setUserId(userId);
        userUnLike.setUnlikeUserId(unlikeId);
        userUnLike.setCreated(System.currentTimeMillis());
        mongoTemplate.save(userUnLike);
    }
}
